package com.example.demo.service.handler;

import com.example.demo.model.WxUser;
import com.example.demo.service.WxUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;

import java.util.Date;
import java.util.Map;

/**
 * 消息类型未事件 的处理类
 */
public class WxEventMessage extends WxMessageAbstractHandler {

    @Override
    public String handlerMessage(Map<String, String> map) {
        String event = map.get("Event");//事件类型
        WxUser wxUser = new WxUser();
        wxUser.setOpenID(map.get("FromUserName"));
        wxUser.setServiceId(map.get("ToUserName"));
        String date_str = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
        if (EVENT_SUB.equals(event)) {
            //存入数据库
            wxUser.setSubStatus("1");//１　订阅
            wxUser.setCreateTime(date_str);
        } else if (EVENT_SUB_UN.equals(event)) {
            wxUser.setSubStatus("2");//取消订阅
            wxUser.setCancelTime(date_str);
        }
        wxUserService.saveOne(wxUser);
        return null;
    }
}
